﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using seejee_Backendium.Core.Interfaces;

namespace seejee_Backendium.Data.Services
{
    public class ConnectionStringFactory : IConnectionStringFactory
    {
        private string _dataSourcesConnectionString;
        private readonly object _lock = new object();

        public void SetDataSourcesConnectionString(string connectionString)
        {
            lock (_lock)
            {
                _dataSourcesConnectionString = connectionString;
            }
        }

        public string GetDataSourcesConnectionString()
        {
            lock (_lock)
            {
                if (string.IsNullOrEmpty(_dataSourcesConnectionString))
                {
                    throw new InvalidOperationException("未设置数据源连接字符串。请先调用 /api/Acc/DB/{DBContent} 接口设置连接字符串");
                }
                return _dataSourcesConnectionString;
            }
        }

        public void ClearDataSourcesConnectionString()
        {
            lock (_lock)
            {
                _dataSourcesConnectionString = null;
            }
        }

        public bool HasDataSourcesConnectionString()
        {
            lock (_lock)
            {
                return !string.IsNullOrEmpty(_dataSourcesConnectionString);
            }
        }
    }
}
